package org.example.demos.pattern.chain_pattern;

import java.util.Iterator;
import java.util.Map;

public abstract class AbstractCheckHandler {

    abstract Object getValue(String field);

    abstract Object checkValue(String field,Map<String,Object> voucher);


    Object checkField(Map<String,Object> voucher,CheckChainContext context ,Iterator<CheckChainContext> it) throws InstantiationException, IllegalAccessException {
        String field = context.getField();
        this.getValue(field);
        this.checkValue(context.getField(),voucher);
        if(it.hasNext()){
            CheckChainContext next = it.next();
            AbstractCheckHandler handler = (AbstractCheckHandler)next.getCheckClass().newInstance();
            handler.checkField(voucher,context,it);
        }
        return null;
    };




}
